package com.zeei.pls.helper;

import java.util.ArrayList;
import java.util.List;

import com.zeei.gis.vo.AreaCodeGisVO;

public class AreaCodeHelper {

	public static List<AreaCodeGisVO> subAreaCodesOf(List<AreaCodeGisVO> sources, String areaCode) {
		List<List<AreaCodeGisVO>> allLevels = new ArrayList<>();
		List<AreaCodeGisVO> currentLevel = new ArrayList<>();
		//currentLevel.add(new AreaCodeGisVO(areaCode));
		allLevels.add(currentLevel);
		
		subAreaCodesOf(sources, allLevels);
		
		List<AreaCodeGisVO> items = new ArrayList<>();
		for(int i = 1; i < allLevels.size(); i++) {
			items.addAll(allLevels.get(i));
		}
		
		return items;
	}
	
	public static void subAreaCodesOf(List<AreaCodeGisVO> sources, List<List<AreaCodeGisVO>> allLevels) {
//		List<AreaCodeGisVO> itemsOfCurrentLevel = allLevels.get(allLevels.size() - 1);
		List<AreaCodeGisVO> itemsOfNextLevel = new ArrayList<AreaCodeGisVO>();
		
//		for(AreaCodeGisVO itemA : itemsOfCurrentLevel) {
//			for(AreaCodeGisVO itemB : sources) {
//				if(itemB.isChildOf(itemA)) {
//					itemsOfNextLevel.add(itemB);
//				}
//			}
//		}
		
		if(itemsOfNextLevel.isEmpty()) {
			return;
		}
		
		allLevels.add(itemsOfNextLevel);
		
		subAreaCodesOf(sources, allLevels);
	}
}
